<template>
	<view class="content">
		<view class="tophead">
			<view :class="['tioline',{tiocurr: currType == item.type}]" v-for="(item,index) in toplist" :key="index" @click="tapnav(item,index)">
				<view class="">
					<text>{{item.title}}</text><!-- <text class="iconfont icon"> {{item.sortType == 'desc' ? '&#xe63a;' : '&#xe63b;'}}</text> -->
				</view>
			</view>
		</view>
		<view class="group">
			<mescroll-body ref="mescrollRef" @init="mescrollInit" :down="downOption" @down="downCallback" @up="upCallback">
				<view class="product_cont">
					<view class="product_list" v-for="(item,index) in bastList" :key="index" @click="goGoods(item)">
						<view class="product_image">
							<image class="product_pic" :src="item.image" mode="aspectFill"></image>
						</view>
						<view class="product_name ellipsis">{{item.storeName}}</view>
						<view class="product_bot">
							<view class="product_price">
								<view class="now_price">
									<!-- <view class="sign iconfont">&#xe604;</view> -->
									<!-- <view class="price">{{item.price}}</view> -->
								</view>
								<view class="now_inter" >{{item.integral}}<text class="intertxt">积分</text></view>

							</view>

							<view class="product_flex">
								<view class="old_price">
									<!-- <view class="sign iconfont old">{{item.otPrice}}积分</view> -->
								</view>
								<view class="product_sale">已售:{{item.sales}}</view>

							</view>
						</view>
					</view>

				</view>
			</mescroll-body>


		</view>

	</view>
</template>

<script>
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				cateId: '', // 分类id、
				toplist: [{
					type: 2,
					title: '默认',
					sortType:'desc'
				}, {
					type: 3,
					title: '积分',
					sortType:'desc'
				}],
				bastList: [],
				downOption: {
					auto: true //是否在初始化后,自动执行downCallback; 默认true
				},
				upOption: {
					auto: true, // 不自动加载
					// page: {
					// 	num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
					// 	size: 10 // 每页数据的数量
					// },
					noMoreSize: 4, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
					empty: {
						tip: '~ 空空如也 ~', // 提示
						btnText: '刷新',
						// 列表第一页无任何数据时,显示的空布局
						// use : 是否启用
						// icon : 空布局的图标路径 (支持网络路径)
						// tip : 提示文本
						// btnText : 按钮文本
						// fixed : 是否使用定位,默认false; 配置fixed为true,以下的top和zIndex才生效 (transform会使fixed失效,所以最终还是会降级为absolute)
						// top : fixed定位的top值 (完整的单位值,如"100rpx", "10%";)
						// zIndex : fixed定位z-index值
					},
					textNoMore: "--我也是有底线的--" //没有更多数据的提示文本
				},
				shopname: '',
				currType: 2,
				sortType:'desc'

			}
		},
		onLoad(options) {
			console.log(options)
			if (Object.keys(options).length != 0) {
				this.cateId = options.cateId;
				this.shopname = options.shopname;
				uni.setNavigationBarTitle({
					title: this.shopname
				});
			}
		},
		methods: {
			// 获取列表
			downCallback() {
				this.mescroll.resetUpScroll(); //调用加载
			},
			upCallback(page) {
				//联网加载数据
				// console.log(page)
				let that = this;
				that.api.integralCategorys({
					page: page.num,
					limit: page.size,
					cateId: that.cateId,
					type:that.currType,
					sortType: that.sortType
				}).then(res => {
					console.log(res)
					let curPageData = res.data.records;
					// 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
					let curPageLen = curPageData.length;
					// 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
					let totalPage = res.data.pages;
					//设置列表数据
					setTimeout(() => { // 模拟效果
						if (page.num == 1) this.bastList = []; //如果是第一页需手动置空列表
						this.bastList = this.bastList.concat(curPageData); //追加新数据
						console.log(this.bastList, "---------");
						// 请求成功,隐藏加载状态
						//方法一(推荐): 后台接口有返回列表的总页数 totalPage
						this.mescroll.endByPage(curPageLen, totalPage);
					}, 500)


				})


			},
			// 商品详情
			goGoods: function(item) {
				uni.navigateTo({
					url: '../../home/goodsDetail/goodsDetail?id=' + item.id,
				});
			},
			// 排序
			tapnav: function (item,index) {
				let that = this;
				this.currType = item.type;
				if (item.type == 1) {
					this.currType = item.type;
					if (that.sortType == 'desc') {
						that.sortType = 'asc';
						that.toplist[index].sortType = 'asc';
					} else {
						that.sortType = 'desc';
						that.toplist[index].sortType = 'desc';
					}
				}
				if (item.type == 2) {
					this.currType = item.type;
					if (that.sortType == 'desc') {
						that.sortType = 'asc';
						that.toplist[index].sortType = 'asc';
					} else {
						that.sortType = 'desc';
						that.toplist[index].sortType = 'desc';
					}
				}
				if (item.type == 3) {
					this.currType = item.type;
					if (that.sortType == 'desc') {
						that.sortType = 'asc';
						that.toplist[index].sortType = 'asc';
					} else {
						that.sortType = 'desc';
						that.toplist[index].sortType = 'desc';
					}
				}
				that.mescroll.resetUpScroll(); //调用加载
				
			}



		},
		onPageScroll: function(e) {
			// console.log(e,"====")
			// let that = this;
			// let scrollTop = e.scrollTop;
			// if (scrollTop > 100) {
			// 	that.colorConfirm = '#E42221';
			// 	that.isShow = true;
			// } else {
			// 	that.colorConfirm = 'transparent';
			// 	that.isShow = false;
			// }
		}
	}
</script>

<style lang="less">
	page {
		width: 100%;
		box-sizing: border-box;
		letter-spacing: 3rpx;
		font-family: 'PingFang SC';
		background: #F5F5F5;

	}

	.content {
		width: 100%;
		box-sizing: border-box;
	}

	.tophead {
		width: 100%;
		box-sizing: border-box;
		position: sticky;
		left: 0;
		top: 0;
		z-index: 9999;
		background: #FFFFFF;
		padding: 15rpx 20rpx;
		display: flex;
		justify-content: flex-start;
		align-items: center;

		.tioline {
			width: 100%;
			box-sizing: border-box;
			line-height: 60rpx;
			text-align: center;

			&.tiocurr {
				color: #E42221;
			}
			.icon {
				font-size: 36rpx;
				font-weight: 600;
			}
		}
	}

	.group {
		width: 100%;
		box-sizing: border-box;
		padding: 26rpx;

		// position: relative;
		// top: 0rpx;
		// left: 0;
		// z-index: 10;
		.product_cont {
			width: 100%;
			box-sizing: border-box;
			padding: 10rpx 0 80rpx 0;
			display: flex;
			justify-content: space-between;
			align-items: center;
			flex-flow: wrap;

			.product_list {
				width: 340rpx;
				box-sizing: border-box;
				background: #FFFFFF;
				border-radius: 8rpx;
				margin-bottom: 20rpx;
				padding-bottom: 20rpx;

				.product_image {
					width: 100%;
					height: 340rpx;
					border-radius: 8rpx 8rpx 0 0;

					.product_pic {
						width: 100%;
						height: 100%;
						border-radius: 8rpx 8rpx 0 0;
					}
				}

				.product_name {
					width: 100%;
					box-sizing: border-box;
					padding: 16rpx;
					font-size: 28rpx;
					color: #212121;
					line-height: 40rpx;
				}

				.product_bot {
					width: 100%;
					box-sizing: border-box;
					// display: flex;
					// justify-content: space-between;
					// align-items: center;
					// line-height: 40rpx;
					padding: 0 16rpx;

					.product_flex {
						width: 100%;
						box-sizing: border-box;
						display: flex;
						justify-content: space-between;
						align-items: center;
						padding-top: 15rpx;
						line-height: 40rpx;

						.product_sale {
							font-size: 26rpx;
							color: #666666;
						}

						.old_price {
							font-size: 24rpx;
							color: #999999;
							text-decoration: line-through;
							padding-left: 10rpx;

							.old {
								font-size: 26rpx;
							}
						}

					}

					.product_price {
						width: 100%;
						box-sizing: border-box;
						display: flex;
						justify-content: flex-start;
						align-items: center;

						.now_price {
							display: flex;
							align-items: center;
							font-size: 36rpx;
							color: #E42221;

							.sign {
								font-size: 32rpx;
								color: #FFDA71;
							}
						}

						.now_inter {
							font-size: 30rpx;
							color: #E42221;

							.intertxt {
								color: #212121;
								font-size: 26rpx;
								margin-left: 5rpx;
							}
						}

					}

				}

			}
		}



	}
</style>
